/**
 * 用户列表模块
 * Created by yuzhou on 16/9/13.
 */

define([
    'vue','debug', 'text!tpl/userList.html',
    'vuex/actions/user'
], function(Vue, Debug, userListHtml, userAction) {

    var debug = Debug('App:Main:ContentUser:UserList')

    return Vue.extend({
        template: userListHtml,
        vuex: {
            getters: {
                page: function(store){ return store.user.page }
            },
            actions: {
                getAllUsers: userAction.getAllUsers,
                updateKeywords: userAction.updateSearchUserKeywords
            }
        },
        components: {
        },
        computed: {
            thisKeywords: {
                get: function() {
                    return this.page.keywords
                },
                set: function(v) {
                    this.updateKeywords(v)
                }
            }
        },
        methods: {
            pull: function(){
                this.getAllUsers(false, false)
            },
            loadMore: function(){
                this.getAllUsers(false, true)
            },
            reload: function(){
                // workaround for tooltip issue
                $('.tooltip').remove()
                this.getAllUsers(true)
            },
            addUser: function() {
                this.$router.go('/user/add')
            },
            edit: function(id) {
                this.$router.go('/user/edit/' + id)
            },
            showDetail: function(id) {
                this.$router.go('/user/show/'+ id)
            },
            testUser: function() {
            }
        },
        init: function(){
            debug('Main ContentUser UserList Component is initialized')
        },
        created: function(){
            debug('Main ContentUser UserList Component is created')
        },
        ready: function(){
            debug('Main ContentUser UserList Component is ready')
            this.getAllUsers()
        }
    })
})